<?php
session_start();
include("db_conn_new.inc");

if(isset($_POST['submiting']) && $_POST['submiting'] == 'emailValidation')
{
	$email = $_POST['EMailAddress1'];
	
//	$sql = "SELECT * FROM crm_contact WHERE Email = '".$email."';";
	
$sql= "SELECT c.Email, ca.PurposeSummary, ca.status FROM `crm_contact` c 
JOIN crm_applicationcontact cac ON cac.ContactID = c.ContactID 
JOIN crm_application ca ON ca.app_id = cac.app_id WHERE c.Email = '".$email."' AND ca.PurposeSummary = 'SACC' AND ca.status != 'close';";
	
	try
	{
		$result = mysql_query($sql);  
		if(mysql_num_rows($result) > 0) 
		{ 
			echo "\"Email Address already registered.\"";
		}
		else
		{
			echo 'true';
		}
	}catch(Execption $e){
		
	}
	
}


if(isset($_POST['submiting']) && $_POST['submiting'] == 'phoneValidation')
{
	$phone = $_POST['Phone1'];
	
	
$sql= "SELECT c.HomePhone, ca.PurposeSummary, ca.status FROM `crm_contact` c 
JOIN crm_applicationcontact cac ON cac.ContactID = c.ContactID 
JOIN crm_application ca ON ca.app_id = cac.app_id WHERE c.HomePhone = '".$phone."' AND ca.PurposeSummary = 'SACC' AND ca.status != 'close';";
	
	try
	{
		$result = mysql_query($sql);
		if(mysql_num_rows($result) > 0)
		{
			echo "\"Phone no already registered.\"";
		}
		else
		{
			echo 'true';
		}
	}catch(Execption $e){
		
	}
	
}

if(isset($_POST['submiting']) && $_POST['submiting'] == 'mobileValidation')
{
	$mobile = $_POST['Mobile1'];
	
	$sql= "SELECT c.Mobile, ca.PurposeSummary, ca.status FROM `crm_contact` c 
JOIN crm_applicationcontact cac ON cac.ContactID = c.ContactID 
JOIN crm_application ca ON ca.app_id = cac.app_id WHERE c.Mobile = '".$mobile."' AND ca.PurposeSummary = 'SACC' AND ca.status != 'close';"; 
	
	try
	{
		$result = mysql_query($sql);
		if(mysql_num_rows($result) > 0)
		{
			echo "\"Mobile No already registered.\"";
		}
		else
		{
			echo 'true';
		}
	}catch(Execption $e){
		
	}
	
}


if(isset($_POST['submiting']) && $_POST['submiting'] == 'checkCurrentPwd')
{
	$currentpassword = $_POST['currentpassword'];
	$user_id = $_SESSION['CurrentContact_id'];
	


$sql = "SELECT * FROM `client_logininfo` WHERE password = '".md5($currentpassword)."' AND CurrentContact_id = ".$user_id.";";

if($result = mysql_query($sql)){
	if(mysql_num_rows($result) > 0)
	{
		echo 'true';
	}
	else
	{
		echo "\"Current password is NOT right.\"";
	}
}
else
{
	echo "\"Current password is should not empty.\"";
}
	


}

?>

